<?php
use Base\AdminController;
use JetBrains\PhpStorm\NoReturn;

class NoticeController extends AdminController
{
    protected string $table = 'notice';

    protected string $model = "notice";

    #[NoReturn] public function init(): void
    {
        $this->routeWhiteLst = ['notice@getlst'];
        if ($this->getRequest()->isGet()) {
            $this->routeWhiteLst[] = 'notice@edit';
        }
        $this->scopeWhere = false;
        parent::init();
    }

    #[NoReturn] public function getLstAction(): void
    {
        try {
            $orgId = $this->scopeOrg();
            $data = NoticeModel::query()
                ->where("status",1)
                ->where(function ($query) use($orgId){
                    $query->where("type",0)
                        ->orWhereIn("org_id",$orgId);
                })
                ->orderBy("id","desc")
                ->limit(6)
                ->get()
                ->toArray();
            $this->apiSuccess($data, "获取成功", 20000);
        }catch (Exception $exception) {
            Log::$customFileName = LOG_PATH."/errors/";
            Log::error($exception->getMessage().$exception->getTraceAsString());
            $this->apiError($exception->getMessage());
        }
    }

}
